package org.yellow.backend.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yellow.backend.mapper.billMapper;
import org.yellow.backend.pojo.bill;

/**
 * @author: hy
 * @create: 2024-01-01
 */
@Service
@SuppressWarnings({"all"})
public class billService {
    @Autowired
    billMapper mapper;

    /**
     * 根据id查询账单
     * @param id
     * @return
     */
    public bill selectBillById(int id){
        return mapper.selectById(id);
    }

    /**
     * 立即支付则修改为 paid
     * @param id
     * @return
     */
    public boolean payNow(int id){
        LambdaUpdateWrapper<bill> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(bill::getBillId,id)
                .set(bill::getStatus, "Paid");

        mapper.update(null, lambdaUpdateWrapper);
        return true;
    }

    /**
     * 之后支付则修改为 unpaid
     * @param id
     * @return
     */
    public boolean payLater(int id){
        LambdaUpdateWrapper<bill> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(bill::getBillId,id)
                .set(bill::getStatus, "Unpaid");

        mapper.update(null, lambdaUpdateWrapper);
        return true;
    }

    /**
     * 退款则将状态修改为 refund
     * @param id
     * @return
     */
    public boolean refund(int id){
        LambdaUpdateWrapper<bill> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(bill::getBillId,id)
                .set(bill::getStatus, "Refund");

        mapper.update(null, lambdaUpdateWrapper);
        return true;
    }
}
